
import store from '@/store'
import axios from 'axios'
import { Message } from 'element-ui'

const service = axios.create({
  baseURL: 'https://likede2-admin.itheima.net/likede'

  // timeout: 5000
})

service.interceptors.request.use((config) => {
  config.headers.Authorization = `${store.getters.token}`
  return config
}, (error) => {
  // 失败执行promise
  return Promise.reject(error)
})
// 响应拦截器
service.interceptors.response.use((response) => {
  // const { msg, success } = response.data
  // if (success) {
  return response.data
  // } else {
  //   Message.error(msg)
  // }
}, async(error) => {
  // error.message
  console.log(error)
  Message.error(error.response?.data?.message || '系统出错，请联系后端程序员')
  return Promise.reject(error)
})

export default service
